﻿namespace ZenSystemService.Api.Services
{
    public static class EntityExtensions
    {
        public static void UpdateFrom<T>(this T entity, object dto) where T : class
        {
            var properties = dto.GetType().GetProperties()
                .Where(p => p.CanWrite && p.PropertyType.IsPublic);

            foreach (var property in properties)
            {
                var value = property.GetValue(dto);
                if (value != null)
                {
                    var entityProperty = entity.GetType().GetProperty(property.Name);
                    entityProperty.SetValue(entity, value, null);
                }
            }
        }
    }
}
